using System;
using System.Collections.Generic;
using System.Text;
using GraphAlgsPresentation.Core;

namespace GraphAlgsPresentation.ScriptLibrary
{
    /// <summary>
    /// Provides a highlight line command
    /// </summary>
    [Serializable]
    public class HighlightLine : Command
    {
        private int _index;
        private bool isReset;

        /// <summary>
        /// Gets or sets the index.
        /// </summary>
        /// <value>The index.</value>
        public int Index
        {
            get { return _index; }
            set { _index = value; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="HighlightLine"/> class.
        /// </summary>
        public HighlightLine()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="HighlightLine"/> class.
        /// </summary>
        /// <param name="index">The index.</param>
        public HighlightLine(int index)
        {
            this.Index = index;
        }

        /// <summary>
        /// Runs this instance.
        /// </summary>
        public override void Run()
        {
            if (this.Context.CommentControl.Lines[Index].BackColor == CommentLine.DefaultBackColor)
                isReset = true;
            else isReset = false;
            this.Context.CommentControl.HighlightLine(this.Index);
        }

        /// <summary>
        /// Undoes this instance.
        /// </summary>
        public override void Undo()
        {
            if (isReset) this.Context.CommentControl.ResetLine(this.Index);
        }
    }
}
